﻿<?php
	include '../inc/conn.php';
	session_start();
	extract($_POST);
	extract($_GET);
	$gmStr=implode(",",$_POST['gmitem']);
	unset($_POST,$_GET);

	if (isset($act))
	{
		if(empty($sku))
		{
			die('机种名没有填写');
		}
		
		if(empty($gmStr))
		{
			die('没有勾选设定的内容');
		}

		$remark=implode("|", $remark);

		if ($act == 'mod' && isset($docid))
		{	
			date_default_timezone_set('Asia/Shanghai');
			$db = new mysql();
			$table = "eng_gmmaker";
			$condition = "docID=${docid}";
			$mod_content="`GMID`='${gmStr}',`SKU`='${sku}', `REMARK`='${remark}'";
			$db->update($table, $mod_content, $condition);
			echo "<script>alert('您提交的数据已成功添加!本窗口将关闭~');window.opener.location.reload();window.close();</script>";
		}
	}
	
	if(!isset($docid)){
		echo "<script>alert('没有找到DOCID!本窗口将关闭~');window.opener.location.reload();window.close();</script>";
		die("没有找到DOCID");
	}

?>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="content-type" content="text/html;charset=utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<!-- <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">-->
	<link rel="stylesheet" href="/css/bootstrap.min.css">
	<script type="text/javascript" src="/js/jquery.min.js"></script>
	<script type="text/javascript" src="/js/jquery-migrate.min.js"></script>
	<script type="text/javascript" src="/js/bootstrap.min.js"></script>
	<title>修改母盘制作执行清单</title>
	<style type="text/css">
		/*首先第一步就是隐藏原来的复选框*/
		.regular-checkbox {
			display: none;
		}
		/*第二部定义现在复选框样式*/
		.regular-checkbox + label {
			position: relative;
			display: inline-block;
			/*lable是内联元素所以需要加inline-block*/
			padding: 7px;
			/*设置复选框大小*/
			background-color: #fafafa;
			/*设置背景颜色*/
			border-radius: 3px;
			/*复选框border*/
			border: 1px solid #CACACA;
			box-shadow: 0 1px 3px rgba(0,0,0,0.5);
			/*创建的阴影效果  这里需要了解box-shadow的属性，前三个值分别是 
				阴影离开横方向的距离   :offset-x
				阴影离开纵方向的距离   ：offset-y
				阴影的模糊半径： 
				阴影的颜色 ：   
			*/
		}
		/*第三部分做一个active的效果*/
		.regular-checkbox + label:active, .regular-checkbox + label:checked + label:active {
			box-shadow: 0 1px 3px rgba(0,0,0,0.05);
		}
				
		/*选中之后的样式*/
		.regular-checkbox:checked + label {
			background-color: #E9ECEE;
			box-shadow: 0 1px 2px rgba(0,0,0,0.05);
		}
		
		/*选中后的效果*/
		.regular-checkbox:checked + label:after {
			content: '\2714';
			/*这是一个对勾*/
			position: absolute;
			font-size: 14px;
			/*设置对勾的大小*/
			top: 0px;
			left: 2px;
			/*设置位置的偏向*/
			color: #009900;
			background-color: #FF0000;
			/*设置颜色绿色*/
			font-weight: bold;
			/*设置对勾的粗细*/
		}
    </style>
</head>
<body class='background'>
	<script type="text/javascript">
		function check(){
			var text=document.getElementById('sku1');
			if (text.value==""){
				alert('机种名没有填写！');
				return false;
			}else{
				alert('准备提交到数据库了~');
				return true;
			}
		}
    </script>
	<div class="container white-background pagecontent">
			<?
				$db = new mysql();
				$db->query("select * from eng_gmmaker where docID=${docid}");
				$num = $db->db_num_rows();
				$row = $db->fetch_assoc();
				echo "<form action='mod_gmmaker.php?act=mod&docid=${docid}' method='post' class='form-inline'>";
				$dbstr = explode(",", $row['GMID']);
				$remarkstr = explode("|", $row['REMARK']);
				echo "<div>\n";
				echo "<label>电子编号</label>\n";
				echo "<input type='text' name='docid' value='${docid}' readonly='true'>\n";
				echo "<label>制作人</label>\n";
				echo "<input type='text' name='owner' value='${row['Owner']}' readonly='true'>\n";
				echo "<label>机种</label>\n";
				echo "<input type='text' name='sku' id='sku1' value='${row['SKU']}'>\n";
				echo "</div>\n";
				echo "<div>\n";
				echo "<table class='table table-hover'><tr><th>项目</th><th>内容描述</th><th>已设定</th><th>备注</th></tr>\n";
				
				$db->query("select * from eng_gmList order by GMID asc");
				$num = $db->db_num_rows();
				for($i=0; $i<$num; $i++){
					$row = $db->fetch_assoc();
					echo "<tr><td>".($i+1)."</td>";
					echo "<td>".htmlspecialchars_decode($row['gm_description'])."</td>";
					if (in_array("${row['GMID']}",$dbstr))
						echo "<td><input type='checkbox' id='check${row['GMID']}' class='regular-checkbox' name='gmitem[]' value='${row['GMID']}' checked='checked' /><label for='check${row['GMID']}'></label></td>";
					else
						echo "<td><input type='checkbox' id='check${row['GMID']}' class='regular-checkbox' name='gmitem[]' value='${row['GMID']}' /><label for='check${row['GMID']}'></label></td>";
					echo "<td><input type='input' name='remark[]' value='$remarkstr[$i]'></td></tr>\n";
				}
				echo "</table>";
				echo "</div>";
				$db->close();
				if(isset($_SESSION['logname'])){
					echo "<div><input class='btn btn-success btn-primary' name='submit' value='提交' type='submit' onclick='return check();'>\n";
					echo "<input class='btn btn-danger' name='reset' value='重写' type='reset'></div>\n";
				}
				echo "</form>\n";
				if(!isset($_SESSION['logname'])){
					include '../bottom.php';
				}
			?>
		
	</div>
</body>
</html>
